import 'package:flutter/material.dart';

import '../global_config.dart';
import '../home/ask_page.dart';
import '../home/follow.dart';
import '../home/hot.dart';
import '../home/recommend.dart';
import '../home/search_page.dart';

class HomePage extends StatefulWidget {
  @override
  _HomePageState createState() => _HomePageState();
}

class _HomePageState extends State<HomePage> {
  Widget barSearch() {
    return new Container(
      child: new Row(
        children: <Widget>[
          new Expanded(
              child: new FlatButton.icon(
                  onPressed: () {
                    Navigator.of(context)
                        .push(new MaterialPageRoute(builder: (context) {
                      return new SearchPage();
                    }));
                  },
                  icon: new Icon(
                    Icons.search,
                    color: GlobalConfig.fontColor,
                    size: 16.0,
                  ),
                  label: new Text(
                    "坚果R1摄像头损坏",
                    style: new TextStyle(
                        color: GlobalConfig.fontColor, fontSize: 16.0),
                  ))),
          new Container(
            width: 1.0,
            height: 14.0,
            decoration: new BoxDecoration(
                border: new BorderDirectional(
                    start: new BorderSide(
              color: GlobalConfig.fontColor,
              width: 1.0,
            ))),
          ),
          new Container(
            child: new FlatButton.icon(
              onPressed: () {
                //todo 跳页
                Navigator.of(context)
                    .push(new MaterialPageRoute(builder: (context) {
                  return new AskPage();
                }));
              },
              icon: new Icon(
                Icons.border_color,
                color: GlobalConfig.fontColor,
                size: 14.0,
              ),
              label: new Text(
                "提问",
                style: new TextStyle(
                    color: GlobalConfig.fontColor, fontSize: 16.0),
              ),
            ),
          )
        ],
      ),
      decoration: new BoxDecoration(
          color: GlobalConfig.searchBackgroundColor,
          borderRadius: new BorderRadius.all(new Radius.circular(4.0))),
    );
  }

  @override
  Widget build(BuildContext context) {
    return new DefaultTabController(
      length: 3,
      child: new Scaffold(
        appBar: new AppBar(
          title: barSearch(),
          bottom: new TabBar(
            tabs: [
              new Tab(text: "关注"),
              new Tab(text: "推荐"),
              new Tab(text: "热榜"),
            ],
            labelColor: GlobalConfig.dark ? Color(0xFF63FDD9) : Colors.blue,
            unselectedLabelColor:
                GlobalConfig.dark ? Colors.white : Colors.black,
          ),
        ),
        body: new TabBarView(children: [
          new Follow(),
          new Recommend(),
          new Hot(),
        ]),
      ),
    );
  }
}
